<template>
  <div class="department" id="department">
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav">
        <!-- 左侧 -->
        <div class="mechanism_nav_left">
          <el-radio-group
            v-model="radio"
            size="small"
            @change="modelType($event)"
          >
            <el-radio-button label="待办"></el-radio-button>
            <el-radio-button label="已办"></el-radio-button>
            <!-- #2b5a9d -->
          </el-radio-group>
        </div>
        <!-- 顶部按钮 -->
        <div class="print">
          <div class="printTable">
            <el-button
              type="primary"
              icon="el-icon-refresh"
              size="small"
              @click="yj_searchForm(getList)"
            ></el-button>
            <el-button
              type="primary"
              icon="el-icon-circle-plus-outline"
              size="small"
              v-if="getList.modelType == '0' && yj_add == true"
              @click="edit('新增')"
            >
              新增
            </el-button>
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="small"
              v-if="getList.modelType == '0' && yj_edit == true"
              @click="edit('编辑')"
            >
              编辑
            </el-button>
            <el-button
              type="primary"
              icon="el-icon-circle-check"
              size="small"
              v-if="getList.modelType == '0' && yj_send == true"
              @click="SubmitText(fId)"
            >
              下发
            </el-button>
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="small"
              v-if="getList.modelType == '0' && yj_receive == true"
              @click="edit('签收')"
            >
              签收
            </el-button>
            <el-button
              type="primary"
              icon="el-icon-delete"
              size="small"
              v-if="getList.modelType == '0' && yj_delete == true"
              @click="rowDelete(fId)"
            >
              删除
            </el-button>
          </div>
        </div>
      </div>

      <!-- 表格 -->
      <div class="text_table">
        <tableData
          :height="navigatepageNums > 1 ? 'calc(100% - 50px)' : '100%'"
          :config="table_config"
          :dataList="tableData"
          :loading="loading"
          @selection-change="selectionChange"
          @sort-change="sortChange"
          @click-change="rowChange"
          @ClickOnLine="yj_viewForm"
          :page="getList.page"
          :pageSize="getList.pageSize"
        />
        <pagination
          v-if="navigatepageNums > 1"
          :info="queryCriteriaData"
          :treelength="treelength"
          :total="queryCriteriaData.total"
          :pageNum.sync="getList.page"
          :limit.sync="getList.pageSize"
          @pagination="yj_searchForm(getList)"
        />
      </div>
      <!--弹框-->
      <div class="Control-1 mechanism_dialogS closure">
        <el-dialog
          :title="dialogTitle"
          :modal-append-to-body="false"
          v-dialogDrag
          :visible.sync="dialogEditVisible"
          v-loading="loadingEditDialog"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)"
        >
          <div
            class="dialogBody common"
            :style="{ height: '650px' }"
            style="overflow: hidden"
          >
            <div style="overflow-y: auto; margin-bottom: 20px; height: 100%">
              <div class="baseTitle">监督工作指令信息</div>
              <div class="publicForm" style="height: 350px; overflow-y: auto">
                <publicForm
                  ref="publicForm"
                  lableWidth="110px"
                  :formObj="FromShow"
                  :formData="formData"
                  :timestamp="formData.fFileurl"
                  :fileList="fSourcefileList"
                  @selectChange="selectChange"
                  @inputChange="inputChange"
                  @delteFile="delteFile"
                  @inputFocus="inputFocus"
                >
                </publicForm>
              </div>
              <div
                class="baseTitle"
                v-if="(Sign == '签收' && signFor == 1) || Sign == '查看'"
              >
                <!-- <div class="baseTitle"> -->
                {{ putAwayCon1 }}
              </div>
              <div
                class="publicForm"
                style="height: 70px; overflow-y: auto"
                v-if="(Sign == '签收' && signFor == 1) || Sign == '查看'"
              >
                <!-- <div class="publicForm" style="height: 70px; overflow-y: auto"> -->
                <publicForm
                  ref="publicForm1"
                  lableWidth="110px"
                  :formObj="putAway1"
                  :formData="formData"
                  @selectChange="selectChange"
                  @inputChange="inputChange"
                >
                </publicForm>
              </div>

              <!-- <div
                class="baseTitle"
                v-if="
                  (Sign == '签收' && signFor == 2) ||
                  (Sign == '查看' && signFor == 0)
                "
              >
                {{ putAwayCon2 }}
              </div> -->
              <!-- <div
                class="publicForm"
                style="height: 70px; overflow-y: auto"
                v-if="
                  (Sign == '签收' && signFor == 2) ||
                  (Sign == '查看' && signFor == 0)
                "
              >
                <publicForm
                  ref="publicForm2"
                  lableWidth="110px"
                  :formObj="putAway2"
                  :formData="formData"
                  @selectChange="selectChange"
                  @inputChange="inputChange"
                >
                </publicForm>
              </div> -->

              <div style="height: 50px"></div>
            </div>
          </div>
          <div class="newlyAdded_btn" v-if="btnShow">
            <el-button
              type="primary"
              @click="yj_saveForm('受检单位1签收')"
              v-if="Sign == '签收' && signFor == 1"
            >
              保存
            </el-button>
            <!-- <el-button
              type="primary"
              @click="yj_saveForm('受检单位2签收')"
              v-if="Sign == '签收' && signFor == 2"
            >
              保存
            </el-button> -->

            <el-button
              type="primary"
              @click="yj_saveForm(0)"
              v-if="Sign == '新增' || Sign == '编辑'"
            >
              保存
            </el-button>
            <el-button type="warning" @click="dialogEditVisible = false">
              关闭
            </el-button>
          </div>
        </el-dialog>
      </div>
      <!--机构树 -->
      <div
        class="Control-1 mechanism_dialogS closure treeData"
        id="department1"
      >
        <el-dialog
          title="选择受检单位"
          :modal-append-to-body="false"
          v-dialogDrag
          :visible.sync="dialogEditVisibleTree"
          v-loading="loadingEditDialogTree"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)"
        >
          <div
            class="dialogBody common"
            :style="{ height: '650px' }"
            style="overflow: hidden"
          >
            <div style="overflow-y: auto; margin-bottom: 50px; height: 100%">
              <tree
                style="height: 100%"
                :treeData="treeData"
                :checkData="checkData"
                nodeKey="fCompanyid"
                @getTreeInfo="handleNodeClick"
                :defaultProps="defaultProps"
              >
              </tree>
            </div>
          </div>
          <div class="newlyAdded_btn">
            <el-button type="primary" @click="yj_saveForm('树')"
              >保存</el-button
            >

            <el-button type="warning" @click="dialogEditVisibleTree = false"
              >关闭</el-button
            >
          </div>
        </el-dialog>
      </div>

      <!-- 根据组织机构树选人---单选 -->
      <div class="Control-1 mechanism_dialogS closure">
        <el-dialog
          :title="candidate"
          :modal-append-to-body="false"
          v-dialogDrag
          :visible.sync="dialogEditVisibleTree_p"
          v-loading="loadingEditDialogTree_p"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)"
        >
          <div
            class="dialogBody common"
            :style="{ height: '650px' }"
            style="overflow: hidden; width: 100%"
          >
            <div style="margin-bottom: 20px; height: 100%; width: 100%">
              <div
                class="publicForm addMemberCheckBox"
                style="height: calc(100% - 40px); overflow-y: auto; width: 100%"
              >
                <div class="addMemberCheckTree">
                  <div class="companyBox">
                    <el-tree
                      :data="companyInfo"
                      :props="defaultProps"
                      @node-click="selectCompany"
                      :highlight-current="highlightBd"
                    ></el-tree>
                  </div>
                  <div class="departmentBox">
                    <div
                      class="departmentTitle"
                      v-for="(item, index) in departmentList"
                      :key="index"
                      @click="seletDepartment(item, index)"
                    >
                      <a
                        href="javascript:;"
                        :class="num === item.fDepartmentId ? 'activetext' : ''"
                        :title="item.fShortName"
                      >
                        {{ item.fShortName }}</a
                      >
                    </div>
                  </div>
                </div>

                <div class="addMemberCheckLeft">
                  <el-radio-group
                    v-model="checkboxGroup1"
                    @change="selectRealname($event, personList)"
                  >
                    <el-radio-button
                      v-for="item in personList"
                      :label="item.fUserid"
                      :key="item.fUserid"
                      :value="item.fRealname"
                    >
                      <div class="addMemberCheck">
                        <div class="MemberIcon">
                          <img :src="item.fGender == 0 ? girls : boys" alt="" />
                        </div>
                        <div class="MemberDetailInfos">
                          <div class="name">{{ item.fRealname }}</div>
                          <div class="hostName">{{ item.fDepartmentName }}</div>
                          <div class="hostName">{{ item.fAccount }}</div>
                        </div>
                      </div>
                    </el-radio-button>
                  </el-radio-group>
                </div>
              </div>
            </div>
          </div>
          <div class="newlyAdded_btn" v-if="btnShow">
            <el-button type="primary" @click="submitMember(0)">保存</el-button>
            <el-button type="warning" @click="dialogEditVisibleTree_p = false"
              >关闭</el-button
            >
          </div>
        </el-dialog>
      </div>

      <!-- 根据组织机构树选人---多选 -->
      <div class="Control-1 mechanism_dialogS closure">
        <el-dialog
          :title="candidate"
          :modal-append-to-body="false"
          v-dialogDrag
          :visible.sync="dialogEditVisibleTree_p2"
          v-loading="loadingEditDialogTree_p2"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)"
        >
          <div
            class="dialogBody common"
            :style="{ height: '650px' }"
            style="overflow: hidden; width: 100%"
          >
            <div style="margin-bottom: 20px; height: 100%; width: 100%">
              <div
                class="publicForm addMemberCheckBox"
                style="height: calc(100% - 40px); overflow-y: auto; width: 100%"
              >
                <div class="addMemberCheckTree">
                  <div class="companyBox">
                    <!-- <el-tree
                      :data="companyInfo"
                      :props="defaultProps"
                      @node-click="selectCompany"
                      :highlight-current="highlightBd"
                    ></el-tree> -->
                    <div
                      class="companyBox_box"
                      v-for="(item, index) in companyInfo"
                      :key="index"
                      @click="selectCompanys(item, index)"
                      :style="{
                        color: item.show === true ? '#fff' : '#555',
                        background:
                          item.show === true ? '#1559ba' : 'aliceblue',
                      }"
                    >
                      {{ item.fShortname }}
                    </div>
                  </div>
                  <div class="departmentBox">
                    <div
                      class="departmentTitle"
                      v-for="(item, index) in departmentList"
                      :key="index"
                      @click="seletDepartment(item, index)"
                    >
                      <a
                        href="javascript:;"
                        :class="num === item.fDepartmentId ? 'activetext' : ''"
                        :title="item.fShortName"
                      >
                        {{ item.fShortName }}</a
                      >
                    </div>
                  </div>
                </div>

                <div class="addMemberCheckLeft addMemberCheckLefts">
                  <el-checkbox-group
                    v-model="checkboxGroup2"
                    @change="selectRealname2($event, personList2)"
                  >
                    <el-checkbox-button
                      v-for="item in personList2"
                      :label="item.fUserid"
                      :key="item.fUserid"
                      :value="item.fRealname"
                    >
                      <div class="addMemberCheck">
                        <div class="MemberIcon">
                          <!--  -->
                          <!-- -->
                          <img :src="item.fGender == 0 ? girls : boys" alt="" />
                        </div>
                        <div class="MemberDetailInfos">
                          <div class="name">{{ item.fRealname }}</div>
                          <div class="hostName">{{ item.fDepartmentName }}</div>
                          <div class="hostName">{{ item.fAccount }}</div>
                        </div>
                      </div>
                    </el-checkbox-button>
                  </el-checkbox-group>
                </div>

                <div class="selectPerson">
                  <div class="selectPersonTitle">
                    已选人员（{{ newData2.length }}人）
                  </div>
                  <div class="selectPersonData">
                    <div
                      class="selectPersonDataBox"
                      v-for="item in newData2"
                      :label="item.fRealname"
                      :key="item.fRealname"
                    >
                      <div class="MemberIcon">
                        <img :src="item.fGender == 0 ? girls : boys" alt="" />
                      </div>
                      <div class="MemberDetailInfo1">
                        <div class="name">{{ item.fRealname }}</div>
                        <div class="hostName">{{ item.fDepartmentName }}</div>
                        <div class="hostName">{{ item.fAccount }}</div>
                      </div>
                      <div
                        class="deleteUser"
                        @click="deteleUser(item.fUserid)"
                      ></div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="newlyAdded_btn" v-if="btnShow">
            <el-button type="primary" @click="submitMember(1)">保存</el-button>
            <el-button type="warning" @click="dialogEditVisibleTree_p2 = false"
              >关闭</el-button
            >
          </div>
        </el-dialog>
      </div>
    </div>
  </div>
</template>
<script>
import {
  getWorkOrderExecutionReport2PageLists, //列表
  getWorkOrderExecutionReport2ByFid, //详情
  saveWorkOrderExecutionReport2, //保存
  saveWorkOrderExecutionReport2BySign1, //签收（受检单位1）
  // saveWorkOrderExecutionReport2BySign2, //签收（受检单位2）
  deleteWorkOrderExecutionReport2, //删除
  commitWorkOrderExecutionReport2, //签发
  getUserCompanyTreeList, //树结构
  getUserCompanyTreeListXm, //受检项目树
  getUserCompanyTreeLists, //受检单位树
  getBaseDepartmentUser, //查人员
} from "@/api/request.js";
import tree from "@/components/QualityGridManage/tree"; //左侧机构树
import TableData from "@/components/HntManage/el-tables"; //主页面列表
import Pagination from "@/components/public/el-pagination"; //主页面分页
import publicForm from "@/components/public/el-form.vue"; //弹框form
import formJs from "../regexDetail.js"; //新增弹框配置项
// import { set } from "vue/types/umd.js";
// import tree from "@/components/public/el-trees"; //左侧机构树

export default {
  // inject: ["reload"],
  name: "distributeText",
  data() {
    return {
      name: "distributeText",
      // 分页
      navigatepageNums: null, //是否显示分页
      queryCriteriaData: {},
      // 分页
      yj_add: null,
      yj_edit: null,
      yj_delete: null,
      yj_send: null,
      yj_receive: null,

      radio: "待办",

      // 列表
      getList: {
        fCompanyid: "", // 左侧选中组织机构id
        page: 1, //页码
        pageSize: 20, //每页条数
        userId: "", // 查询待办或已办时传 列表页查询不传
        modelType: "", // 0-待办 1-已办 传2 表示列表页查询 复查编辑页：待办3   已办4
        fQualitygridclass: "", // 上方查询条件质量网格
        fQualitygridtype: "", // 上方查询条件工程网格
      },
      fId: null, //当前行数据fId
      row: { fstatus: "" }, //选中行
      loading: false, //列表转载
      table_config: formJs.table_configText,
      tableData: [], //表格列表数据列表
      // 列表

      // 弹框
      Sign: "",
      timeYMD: null, //当前日期
      btnShow: true,
      dialogTitle: "",
      loadingEditDialog: false, //弹框loading
      dialogEditVisible: false, //新增弹框是否显示
      FromShow: formJs.FromShowText1, //下发
      FromShowText1: formJs.FromShowText1, //下发---编辑
      FromShowLook1: formJs.FromShowLook1, //下发---查看
      // FromShowText2: formJs.FromShowText2, //下发(2受检单位）---编辑
      // FromShowLook2: formJs.FromShowLook2, //下发(2受检单位）---查看

      putAwayCon1: "受检单位1签收",
      putAway1: formJs.putAwayText1, //签收
      putAwayText1: formJs.putAwayText1, //签收---编辑
      putAwayLook1: formJs.putAwayLook1, //签收---查看
      // putAwayCon2: "受检单位2签收",
      // putAway2: formJs.putAwayText2, //签收
      // putAwayText2: formJs.putAwayText2, //签收---编辑
      // putAwayLook2: formJs.putAwayLook2, //签收---查看
      signFor: null, //判断签收展示

      formData: formJs.formData,
      CcpeoplesUserList: [], //复选人员框
      recordfiles: [], //删除文件
      fSourcefileList: [],
      saveData: {},
      getUserList: [],
      // 机构树
      dialogEditVisibleTree: false,
      loadingEditDialogTree: false,
      checked: true, //查看下级按钮
      companyTree: "", //所有数据
      treeData: [], //左侧树状图数据
      checkData: [], //树状图默认选中id
      treeRow: { fCompanyids: null }, //选中树数据--受检项目
      treeRows: null, //选中树数据--受检单位
      // 机构树
      // 树选人
      defaultProps: {
        children: "children",
        label: "fShortname",
      },
      highlightBd: true, //左侧机构树停留背景色
      dialogEditVisibleTree_p: false,
      loadingEditDialogTree_p: false,
      companyInfo: [], //公司树信息
      departmentList: [], //部门
      num: null,
      personList: [], //人员列表新增
      checkboxGroup1: [],
      boys: require("@/assets/img/organization/boys.png"),
      girls: require("@/assets/img/organization/girls.png"),
      newData: null,
      treeText: {
        companyId: null,
        userId: null,
        text: null,
      },
      propText: null,
      candidate: null,
      // 树选人--多选
      checkboxGroup2: [],
      dialogEditVisibleTree_p2: false,
      loadingEditDialogTree_p2: false,
      newData2: [],
      propText2: null,
      allUserInfo: [],
      userList: [],
      userListId: [],
      getUserInitialList: [], //抄送人初始列表
      personList2: [], //人员列表新增
      // 树选人--多选
      // 树选人
      // 弹框

      userInfo: {}, //登录用户
    };
  },
  components: {
    TableData, //主页面列表
    Pagination, //分页
    publicForm, //表单
    tree, //机构树
  },
  created() {},
  mounted() {
    this.userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
    // console.log("userInfo", this.userInfo);
    this.getList = {
      fCompanyid: this.userInfo.companyId, // 左侧选中组织机构id
      userId: this.userInfo.userId, // 查询待办或已办时传 列表页查询不传
      page: 1, //页码
      pageSize: 20, //每页条数
      modelType: "0", // 0代办 1已办 不传或传空 表示列表页查询
      fQualitygridclass: "", // 上方查询条件质量网格
      fQualitygridtype: "", // 上方查询条件工程网格
    };

    this.getData();
    this.yj_searchForm(this.getList);
    this.btnRole(this.name);

    this.table_config.operation.cols = [
      {
        prop: "fstatus",
        type: "primary",
        handleRow: this.handleRow,
      },
    ];
    this.table_config.operation["specialClass"] = function (rowData) {
      var color = null;
      if (rowData == "待签收") {
        color = "red !important";
      } else if (rowData == "执行中") {
        color = "orange !important";
      } else if (rowData == "已结束") {
        color = "green !important";
      } else {
        color = "#409eff !important";
      }
      return color;
    };
  },
  methods: {
    btnRole(name) {
      var btnList = [];
      var ModuleList = JSON.parse(sessionStorage.getItem("ModuleList"));
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });
        this.yj_add = btnStr.includes("yj_add");
        this.yj_edit = btnStr.includes("yj_edit");
        this.yj_delete = btnStr.includes("yj_delete");
        this.yj_send = btnStr.includes("yj_send");
        this.yj_receive = btnStr.includes("yj_receive");
      } else {
        this.yj_add = true;
        this.yj_edit = true;
        this.yj_delete = true;
        this.yj_send = true;
        this.yj_receive = true;
      }
    },
    modelType(e) {
      this.fId = "";
      if (e == "待办") {
        this.getList.modelType = "0";
        this.getList.userId = this.userInfo.userId;
      } else {
        this.getList.modelType = "1";
        this.getList.userId = this.userInfo.userId;
      }
      this.yj_searchForm(this.getList);
    },
    // 获取列表数据
    yj_searchForm(id) {
      this.row = { fstatus: "" }; //选中行
      this.loading = true;
      getWorkOrderExecutionReport2PageLists(id)
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            that.loading = false;
            that.tableData = res.data.pageInfo.list;
            that.queryCriteriaData = res.data.pageInfo;
            that.navigatepageNums =
              that.queryCriteriaData.navigatepageNums.length;
          } else {
            this.$message.error("列表", res.msg);
            this.loading = false;
          }
        })
        .catch(() => {
          this.loading = false;
        });
    },
    // 新增/编辑/签收
    edit(title) {
      this.Sign = title;
      this.dialogTitle = title;
      this.recordfiles = [];
      this.fSourcefileList = [];
      this.btnShow = true;
      this.FromShow = this.FromShowText1;
      if (title == "新增") {
        if (this.userInfo.companyNature == "施工单位") {
          this.$message.error("当前账户无法新增");
        } else {
          this.newData = [];
          this.checkboxGroup1 = [];
          var fOrderfile = "GZZLZXXF" + new Date().valueOf();
          // var companyNature = "集团公司指令";
          var companyNature = null;
          if (this.userInfo.companyNature == "集团公司") {
            companyNature = "集团公司指令";
          } else if (this.userInfo.companyNature == "分子公司") {
            companyNature = "分子公司指令";
          } else if (this.userInfo.companyNature == "建设单位") {
            companyNature = "项目公司指令";
          } else if (this.userInfo.companyNature == "总监办") {
            companyNature = "监理单位指令";
          }
          if (companyNature != "集团公司指令") {
            this.FromShow[5].disabled = true;
            this.FromShow[5].rules[0].required = false;
          } else {
            this.FromShow[5].disabled = false;
            this.FromShow[5].rules[0].required = true;
          }

          // disabled: false, //是否禁用
          //   rules: [{
          //       required: true,
          //       message: '请选择受检项目'
          //   }]

          this.formData = {
            fId: "", //传fid代表修改 不传代表新增
            fProjectname: this.userInfo.projectName, // 当前登录人项目名称
            fProjectid: this.userInfo.projectId, // 当前登录人项目ID
            fCompanyname: this.userInfo.companyName, // 当前登录人标段名称
            fCompanyid: this.userInfo.companyId, // 当前登录人标段ID
            fProjectfullname: "",
            fCompanyfullname: "",
            fIssueunit: this.userInfo.companyName, //下发指令单位
            fIssueunitid: this.userInfo.companyId, //下发指令单位id
            fUnittype: companyNature, //单位类型
            // fUnittype: '', //单位类型
            fOrdernumber: "", // 指令单编号  有填  无"/"
            fStartcheckdates: this.timeYMD, //检查日期起始
            fEndcheckdates: this.timeYMD, //检查日期结束
            fCheckunit: "", //受检单位1
            fCheckunitid: "", //受检单位id1
            fCheckunit2: "", //受检单位2
            fCheckunit2id: "", //受检单位2
            fCheckproject: "", //受检项目
            fCheckprojectid: "", //受检项目id
            fProblemdescription: "", //存在的问题概述
            fChangerequirements: "", //整改措施及要求
            fRequesttermdates: this.timeYMD, //要求整改期限
            fFileurl: fOrderfile, //附件资料
            // fCheckdepartment: this.userInfo.companyName, //检查部门
            fCheckdepartment: "", //检查部门
            fCheckinspectors: "", //检查人员姓名
            fSubsignid1: "", //指定签收人1id
            fSubsignname1: "", //指定签收人1姓名
            fSubsignid2: "", //指定签收人2id
            fSubsignname2: "", //指定签收人2姓名
            fReportname: this.userInfo.realName, // 填报人姓名
            fReportid: this.userInfo.userId, // 填报人id
            fReportdates: this.timeYMD, // 填报日期
            fReportdate: null,

            fCcpeople: "", //抄送人姓名数组
            fCcpeopleid: "", //抄送人id数组
            fCcpeople2: "", //抄送人2姓名
            fCcpeopleid2: "", //抄送人2id
            userId: this.userInfo.userId, //当前登录人id
            userName: this.userInfo.realName, //当前登录人姓名
            recordfiles: [], //删除文件id集合
          };
          this.dialogEditVisible = true;
        }
      } else if (title == "签收") {
        if (this.fId == "" || this.fId == null) {
          this.$message.error("请先选择需要签收的数据");
        } else {
          if (this.row.fstatus == "待签收") {
            this.FromShow = this.FromShowLook1;
            this.putAway1 = this.putAwayText1;
            // this.putAway2 = this.putAwayText2;
            this.loadingEditDialog = true; //弹框loading
            this.dialogEditVisible = true;
            this.getConcrete(this.fId);
          } else {
            this.$message.error("请选择信息状态为‘待签收’的数据");
          }
        }
      } else if (title == "编辑") {
        if (this.fId == "" || this.fId == null) {
          this.$message.error("请先选择需要编辑的数据");
        } else {
          if (this.row.fstatus == "编辑中") {
            this.loadingEditDialog = true; //弹框loading
            this.dialogEditVisible = true;
            this.getConcrete(this.fId);
          } else {
            this.$message.error("请选择信息状态为‘编辑中’的数据");
          }
        }
      }
    },
    // 获取详情
    getConcrete(id) {
      getWorkOrderExecutionReport2ByFid({ fId: id })
        .then((res) => {
          if (res.errcode == 0) {
            this.loadingEditDialog = false; //弹框loading
            this.formData = res.data.yjQmpMsWrokorderExecutionreport2;

            if (this.Sign == "签收") {
              // // 判断监督工作指令信息展示
              // if (
              //   this.formData.fCheckunit2 != "" &&
              //   this.formData.fCheckunit2 != null
              // ) {
              //   this.FromShow = this.FromShowLook2;
              // } else {
              //   this.FromShow = this.FromShowLook1;
              // }

              // 判断是第几个受检单位
              if (this.userInfo.userId == this.formData.fSubsignid1) {
                this.signFor = 1;
                this.putAwayCon1 = "受检单位签收";
                // 签收单位1
                if (
                  this.formData.fSignunit1 == "" ||
                  this.formData.fSignunit1 == null
                ) {
                  this.formData.fSignunit1 = this.userInfo.companyName;
                }
                // 签收人1
                if (
                  this.formData.fSignid1 == "" ||
                  this.formData.fSignid1 == null ||
                  this.formData.fSignname1 == "" ||
                  this.formData.fSignname1 == null
                ) {
                  this.formData.fSignname1 = this.userInfo.realName; //签收人
                  this.formData.fSignid1 = this.userInfo.userId;
                }
                // 签收时间1
                if (
                  this.formData.fSigndate1s == "" ||
                  this.formData.fSigndate1s == null
                ) {
                  this.formData.fSigndate1s = this.timeYMD; //签收日期
                }
              }
              // if (this.userInfo.userId == this.formData.fSubsignid2) {
              //   this.signFor = 2;
              //   this.putAwayCon2 = "受检单位签收";
              //   // 签收单位2
              //   if (
              //     this.formData.fSignunit2 == "" ||
              //     this.formData.fSignunit2 == null
              //   ) {
              //     this.formData.fSignunit2 = this.userInfo.companyName;
              //   }
              //   // 签收人2
              //   if (
              //     this.formData.fSignid2 == "" ||
              //     this.formData.fSignid2 == null ||
              //     this.formData.fSignname2 == "" ||
              //     this.formData.fSignname2 == null
              //   ) {
              //     this.formData.fSignname2 = this.userInfo.realName; //签收人
              //     this.formData.fSignid2 = this.userInfo.userId;
              //   }
              //   // 签收时间2
              //   if (
              //     this.formData.fSigndate2s == "" ||
              //     this.formData.fSigndate2s == null
              //   ) {
              //     this.formData.fSigndate2s = this.timeYMD; //签收日期
              //   }
              // }
            } else {
              // 编辑

              //// 判断两个受检单位
              // if (
              //   this.formData.fCheckunit2 != "" &&
              //   this.formData.fCheckunit2 != null
              // ) {
              //   this.FromShow = this.FromShowText2;
              // } else {
              //   this.FromShow = this.FromShowText1;
              // }

              //项目名称
              if (
                this.formData.fProjectname == "" ||
                this.formData.fProjectname == null ||
                this.formData.fProjectid == "" ||
                this.formData.fProjectid == null
              ) {
                this.formData.fProjectname = this.userInfo.projectName; // 项目名称
                this.formData.fProjectid = this.userInfo.projectId;
              }
              //标段名称
              if (
                this.formData.fCompanyname == "" ||
                this.formData.fCompanyname == null ||
                this.formData.fCompanyid == "" ||
                this.formData.fCompanyid == null
              ) {
                this.formData.fCompanyname = this.userInfo.companyName; // 标段名称
                this.formData.fCompanyid = this.userInfo.companyId;
              }
              //下发指令单位
              if (
                this.formData.fIssueunit == "" ||
                this.formData.fIssueunit == null ||
                this.formData.fIssueunitid == "" ||
                this.formData.fIssueunitid == null
              ) {
                this.formData.fIssueunit = this.userInfo.companyName; // 下发指令单位
                this.formData.fIssueunitid = this.userInfo.companyId;
              }
              //检查日期起始
              if (
                this.formData.fStartcheckdates == "" ||
                this.formData.fStartcheckdates == null
              ) {
                this.formData.fStartcheckdates = this.timeYMD; // 检查日期起始
              }
              //检查日期结束
              if (
                this.formData.fEndcheckdates == "" ||
                this.formData.fEndcheckdates == null
              ) {
                this.formData.fEndcheckdates = this.timeYMD; // 检查日期结束
              }
              //要求整改期限
              if (
                this.formData.fRequesttermdates == "" ||
                this.formData.fRequesttermdates == null
              ) {
                this.formData.fRequesttermdates = this.timeYMD;
              }
              //要求整改期限
              if (
                this.formData.fRequesttermdates == "" ||
                this.formData.fRequesttermdates == null
              ) {
                this.formData.fRequesttermdates = this.timeYMD;
              }
              //要求整改期限
              if (
                this.formData.fRequesttermdates == "" ||
                this.formData.fRequesttermdates == null
              ) {
                this.formData.fRequesttermdates = this.timeYMD;
              }
              //附件资料
              if (
                this.formData.fFileurl == "" ||
                this.formData.fFileurl == null
              ) {
                var fOrderfile = "GZZLZXXF" + new Date().valueOf();
                this.formData.fFileurl = fOrderfile;
              }
              //检查部门
              if (
                this.formData.fCheckdepartment == "" ||
                this.formData.fCheckdepartment == null
              ) {
                this.formData.fCheckdepartment = this.userInfo.companyName;
              }
              //填报人
              if (
                this.formData.fReportname == "" ||
                this.formData.fReportname == null ||
                this.formData.fReportid == "" ||
                this.formData.fReportid == null
              ) {
                this.formData.fReportname = this.userInfo.realName;
                this.formData.fReportid = this.userInfo.userId;
              }
              //当前登录人
              if (
                this.formData.userName == "" ||
                this.formData.userName == null ||
                this.formData.userId == "" ||
                this.formData.userId == null
              ) {
                this.formData.userName = this.userInfo.realName;
                this.formData.userId = this.userInfo.userId;
              }
              //填报日期
              if (
                this.formData.fReportdates == "" ||
                this.formData.fReportdates == null
              ) {
                this.formData.fReportdates = this.timeYMD;
              }
            }
            this.fSourcefileList = res.data.fFileurllist; //工作指令资料附件
          } else {
            this.loadingEditDialog = false; //弹框loading
            return this.$message.error(res.msg);
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },

    // 保存
    yj_saveForm(num) {
      console.log(num);
      if (num == 0) {
        if (this.$refs.publicForm.submitForm()) {
          // if (this.fSourcefileList.length != 0) {
          this.saveData = {
            fId: this.formData.fId, //传此表示修改
            fProjectname: this.userInfo.projectName, // 当前登录人项目名称
            fProjectid: this.userInfo.projectId, // 当前登录人项目ID
            fCompanyname: this.userInfo.companyName, // 当前登录人标段名称
            fCompanyid: this.userInfo.companyId, // 当前登录人标段ID
            fProjectfullname: this.formData.fProjectfullname,
            fCompanyfullname: this.formData.fCompanyfullname,
            fIssueunit: this.formData.fIssueunit, //下发指令单位
            fIssueunitid: this.formData.fIssueunitid, //下发指令单位id
            fUnittype: this.formData.fUnittype, //单位类型
            fOrdernumber: this.formData.fOrdernumber, //工作指令编号
            fStartcheckdates: this.formData.fStartcheckdates, //检查日期起始
            fEndcheckdates: this.formData.fEndcheckdates, //检查日期结束
            fCheckunit: this.formData.fCheckunit, //受检单位1
            fCheckunitid: this.formData.fCheckunitid, //受检单位id1
            fCheckunit2: this.formData.fCheckunit2, //受检单位2
            fCheckunit2id: this.formData.fCheckunit2id, //受检单位2
            fCheckproject: this.formData.fCheckproject, //受检项目
            fCheckprojectid: this.formData.fCheckprojectid, //受检项目
            fProblemdescription: this.formData.fProblemdescription, //存在的问题概述
            fChangerequirements: this.formData.fChangerequirements, //整改措施及要求
            fRequesttermdates: this.formData.fRequesttermdates, //要求整改期限
            fFileurl: this.formData.fFileurl, //附件资料
            fCheckdepartment: this.formData.fCheckdepartment, //检查部门
            fCheckinspectors: this.formData.fCheckinspectors, //检查人员姓名
            fSubsignid1: this.formData.fSubsignid1, //指定签收人1id
            fSubsignname1: this.formData.fSubsignname1, //指定签收人1姓名
            fSubsignid2: this.formData.fSubsignid2, //指定签收人2id
            fSubsignname2: this.formData.fSubsignname2, //指定签收人2姓名
            fReportid: this.formData.fReportid, //填报人id'
            fReportname: this.formData.fReportname, //填报人姓名
            fReportdate: this.formData.fReportdate,
            fReportdates: this.formData.fReportdates, //填报时间
            fCcpeople: this.formData.fCcpeople, //抄送人姓名数组
            fCcpeopleid: this.formData.fCcpeopleid, //抄送人id数组
            fCcpeople2: this.formData.fCcpeople2, //抄送人2姓名数组
            fCcpeopleid2: this.formData.fCcpeopleid2, //抄送人2id数组
            userId: this.userInfo.userId, //当前登录人id
            userName: this.userInfo.realName, // 当前登录人名称
            recordfiles: this.recordfiles, // 删除文件id集合
          };
          saveWorkOrderExecutionReport2(this.saveData)
            .then((res) => {
              if (res.errcode == 0) {
                this.yj_searchForm(this.getList);
                this.dialogEditVisible = false;
                this.$message.success("新增成功");
              } else {
                this.$message.error(res.msg);
                console.log("接口报错");
              }
            })
            .catch((error) => {
              console.log(error);
            });
          // } else {
          //   this.$message.error("请上传附件资料");
          // }
        } else {
          console.log("error");
        }
      } else if (num == "受检单位1签收") {
        if (this.$refs.publicForm1.submitForm()) {
          var saveData1 = {
            fId: this.formData.fId, //当前fid
            fSignunit1: this.formData.fSignunit1, //受检单位1 签收单位
            fSigndescription1: this.formData.fSigndescription1, //受检单位1 签收说明
            fSignid1: this.formData.fSignid1, //受检单位1 签收人id
            fSignname1: this.formData.fSignname1, //受检单位1 签收人姓名
            fSigndate1s: this.formData.fSigndate1s, //受检单位1 签收时间
          };
          saveWorkOrderExecutionReport2BySign1(saveData1)
            .then((res) => {
              if (res.errcode == 0) {
                this.yj_searchForm(this.getList);
                this.dialogEditVisible = false;
                this.$message.success("签收成功");
              } else {
                this.$message.error(res.msg);
                console.log("签收接口报错");
              }
            })
            .catch((error) => {
              console.log(error, "签收接口报错");
            });
        } else {
          console.log("error");
        }
      }
      //  else if (num == "受检单位2签收") {
      //   if (this.$refs.publicForm2.submitForm()) {
      //     var saveData2 = {
      //       fId: this.formData.fId, //当前fid
      //       fSignunit2: this.formData.fSignunit2, //受检单位2 签收单位
      //       fSigndescription2: this.formData.fSigndescription2, //受检单位2 签收说明
      //       fSignid2: this.formData.fSignid2, //受检单位2 签收人id
      //       fSignname2: this.formData.fSignname2, //受检单位2 签收人姓名
      //       fSigndate2s: this.formData.fSigndate2s, //受检单位2 签收时间
      //     };
      //     saveWorkOrderExecutionReport2BySign2(saveData2)
      //       .then((res) => {
      //         if (res.errcode == 0) {
      //           this.yj_searchForm(this.getList);
      //           this.dialogEditVisible = false;
      //           this.$message.success("签收成功");
      //         } else {
      //           this.$message.error(res.msg);
      //           console.log("签收接口报错");
      //         }
      //       })
      //       .catch((error) => {
      //         console.log(error, "签收接口报错");
      //       });
      //   } else {
      //     console.log("error");
      //   }
      // }
      else if (num == "树") {
        this.formData.fSubsignname1 = "";
        this.formData.fSubsignid1 = "";
        this.formData.fCcpeople = "";
        this.formData.fCcpeopleid = "";
        // 受检单位
        if (this.propText == "fCheckunit") {
          if (this.formData.fCheckunit != this.treeRows.fFullname) {
            this.formData.fCheckproject = "";
            this.formData.fCheckprojectid = "";
            this.FromShow = this.FromShowText1;
          }
          this.formData.fCheckunit = this.treeRows.fFullname;
          this.formData.fCheckunitid = this.treeRows.fCompanyid;

          this.getPerson(this.treeRows.fCompanyid);
        }
        // 受检项目
        if (this.propText == "fCheckproject") {
          if (this.treeRow.fNature == "施工单位") {
            this.formData.fCheckproject = this.treeRow.fShortname;
            this.formData.fCheckprojectid = this.treeRow.fCompanyid;
            //// 判断两个受检单位
            if (
              this.formData.fUnittype == "集团公司指令" &&
              this.treeRow.fCompanyids != null &&
              this.treeRow.fCompanyids != ""
            ) {
              //   this.FromShow = this.FromShowText2;
              this.formData.fCheckunit2 = this.treeRow.fCompanynames;
              this.formData.fCheckunit2id = this.treeRow.fCompanyids;
            } else {
              //   this.FromShow = this.FromShowText1;
              this.formData.fCheckunit2 = "";
              this.formData.fCheckunit2id = "";

              //   this.formData.fSubsignid2 = "";
              //   this.formData.fSubsignname2 = "";

              //   this.formData.fCcpeople2 = "";
              //   this.formData.fCcpeopleid2 = "";
            }
            //// 判断两个受检单位
          } else {
            return this.$message.warning("请选择施工单位");
          }
        }
        this.dialogEditVisibleTree = false;
      }
    },
    getPerson(data) {
      var obj = {
        fCompanyid: data,
      };
      getBaseDepartmentUser(obj)
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.childList[0].personList;
            //工作计划信息新增options
            // formObj
            var personList = [];
            arr.map((item) => {
              personList.push({
                label: item.fRealname,
                value: item.fUserid,
              });
            });
            this.FromShowText1[13].options = personList;

            // this.formObj[10].options = personList;
            // this.formObj[11].options = personList;
            // this.formFinishObj[6].options = personList;
            // this.formFinishObj[7].options = personList;
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    // 签发
    SubmitText(id) {
      if (id != "" && id != null) {
        if (this.row.fstatus == "编辑中") {
          this.$confirm("是否继续签发?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              this.loading = true;
              commitWorkOrderExecutionReport2({
                fId: id,
                userId: this.userInfo.userId,
                userName: this.userInfo.realName,
              })
                .then((res) => {
                  if (res.errcode == 0) {
                    this.loading = false;
                    this.yj_searchForm(this.getList);
                    this.$message.success("签发成功");
                  } else {
                    this.$message.error("签发失败", res.msg);
                    this.loading = false;
                  }
                })
                .catch(() => {
                  console.log("签发失败");
                  this.loading = false;
                });
            })
            .catch(() => {
              this.$message("取消签发");
            });
        } else {
          return this.$message.error("请选择信息状态为‘编辑中’的数据");
        }
      } else {
        return this.$message.error("请先选择需要签发的数据");
      }
    },
    // 删除
    rowDelete(id) {
      if (id != "" && id != null) {
        if (this.row.fstatus == "编辑中") {
          this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              this.loading = true;
              deleteWorkOrderExecutionReport2({ fId: id })
                .then((res) => {
                  if (res.errcode == 0) {
                    this.loading = false;
                    this.yj_searchForm(this.getList);
                    this.$message.success("删除成功");
                  } else {
                    this.$message.error("删除失败", res.msg);
                    this.loading = false;
                  }
                })
                .catch(() => {
                  console.log("删除失败");
                  this.loading = false;
                });
            })
            .catch(() => {
              this.$message("取消删除");
            });
        } else {
          return this.$message.error("请选择信息状态为‘编辑中’的数据");
        }
      } else {
        return this.$message.error("请先选择需要删除的数据");
      }
    },

    // 点击查看
    yj_viewForm(row, label) {
      this.row = row;
      this.fId = row.fId;
      if (label == "下发指令单位") {
        this.editText(this.fId);
      }
    },
    // 查看
    editText(id) {
      this.putAway1 = this.putAwayLook1;
      // this.putAway2 = this.putAwayLook2;

      this.dialogTitle = "查看";
      this.Sign = "查看";
      this.btnShow = false;
      if (id != "" && id != null) {
        this.loadingEditDialog = true; //弹框loading
        this.dialogEditVisible = true;
        getWorkOrderExecutionReport2ByFid({ fId: id })
          .then((res) => {
            if (res.errcode == 0) {
              var that = this;
              // if (
              //   res.data.yjQmpMsWrokorderExecutionreport2.fCheckunit2 != "" &&
              //   res.data.yjQmpMsWrokorderExecutionreport2.fCheckunit2 != null
              // ) {
              //   that.FromShow = that.FromShowLook2;
              //   this.putAwayCon1 = "受检单位1签收";
              //   this.putAwayCon2 = "受检单位2签收";
              //   this.signFor = 0;
              // } else {
              that.FromShow = that.FromShowLook1;
              this.putAwayCon1 = "受检单位签收";
              this.signFor = 1;
              // }

              that.loadingEditDialog = false;
              that.fSourcefileList = res.data.fFileurllist; //工作指令资料附件
              that.formData = res.data.yjQmpMsWrokorderExecutionreport2;
            } else {
              this.$message.error("查看", res.msg);
              this.loadingEditDialog = false;
            }
          })
          .catch(() => {
            console.log("查看---详情接口报错");
            this.loadingEditDialog = false;
          });
      } else {
        return this.$message.error("请先选择需要查看的数据");
      }
    },
    getData() {
      var time = new Date();
      const y = time.getFullYear();
      const m = (time.getMonth() + 1 + "").padStart(2, "0");
      const d = (time.getDate() + "").padStart(2, "0");
      this.timeYMD = `${y}-${m}-${d}`;
    },
    // 点击当前
    rowChange(val) {
      this.row = val;
      this.fId = val.fId;
    },
    // 刪除
    delteFile(file) {
      for (let index = 0; index < this.fSourcefileList.length; index++) {
        if (file.uid == this.fSourcefileList[index].uid) {
          if (this.fSourcefileList[index].atta == undefined) {
            this.recordfiles.push({
              fId: this.fSourcefileList[index].fId,
            });
          } else {
            this.recordfiles.push({
              fId: this.fSourcefileList[index].atta.fId,
            });
          }
          this.fSourcefileList.splice(index, 1);
        }
      }
    },
    inputChange(value, index, prop) {
      // console.log("inputChange", value, index, prop);
      return value, index, prop;
    },
    inputFocus(index, prop) {
      // console.log("inputFocus", index, prop);
      this.propText = prop;
      // 受检单位
      if (prop == "fCheckunit") {
        if (
          this.formData.fIssueunitid != "" &&
          this.formData.fIssueunitid != null
        ) {
          this.getTrees(this.formData.fIssueunitid);
        } else {
          this.$message.warning("请先选择下发指令单位");
        }
      }
      // 受检项目
      if (prop == "fCheckproject") {
        if (
          this.formData.fCheckunitid != "" &&
          this.formData.fCheckunitid != null
        ) {
          this.getTree(this.formData.fCheckunitid);
        } else {
          this.$message.warning("请先选择受检单位");
        }
      }
      // 指定签收人1
      if (prop == "fSubsignname1") {
        if (
          this.formData.fCheckunitid == "" ||
          this.formData.fCheckunitid == null
        ) {
          this.$message.error("请先选择受检单位");
        } else {
          // this.candidate = "选择指定签收人1";
          this.candidate = "选择指定签收人";
          this.treeText.companyId = this.formData.fCheckunitid;
          this.treeText.userId = this.formData.fCheckunit;
          this.getBaseCompanyList(this.treeText, prop);
        }
      }
      // // 指定签收人2
      // if (prop == "fSubsignname2") {
      //   if (
      //     this.formData.fCheckunit2id == "" ||
      //     this.formData.fCheckunit2id == null
      //   ) {
      //     this.$message.error("受检单位2不能为空");
      //   } else {
      //     this.candidate = "选择指定签收人2";
      //     this.treeText.companyId = this.formData.fCheckunit2id;
      //     this.treeText.userId = this.formData.fCheckunit2;
      //     this.getBaseCompanyList(this.treeText, prop);
      //   }
      // }
      // 抄送人1
      if (prop == "fCcpeople") {
        //
        if (this.formData.fUnittype != "集团公司指令") {
          if (
            this.formData.fIssueunitid == "" || //下发指令单位id
            this.formData.fIssueunitid == null ||
            this.formData.fCheckunitid == "" || ////受检单位id1
            this.formData.fCheckunitid == null
          ) {
            this.$message.error("请先填写 下发指令单位、受检单位");
          } else {
            // this.candidate = "选择抄送人1";
            this.candidate = "选择抄送人";
            this.treeText.companyId = this.formData.fIssueunitid;
            this.treeText.userId = this.userInfo.userId;
            this.getBaseCompanyList(this.treeText, prop);
          }
        } else {
          if (
            this.formData.fIssueunitid == "" || //下发指令单位id
            this.formData.fIssueunitid == null ||
            this.formData.fCheckunitid == "" || ////受检单位id1
            this.formData.fCheckunitid == null ||
            this.formData.fCheckprojectid == "" || //受检项目id
            this.formData.fCheckprojectid == null
          ) {
            this.$message.error("请先填写 下发指令单位、受检单位、受检项目");
          } else {
            // this.candidate = "选择抄送人1";
            this.candidate = "选择抄送人";
            this.treeText.companyId = this.formData.fIssueunitid;
            this.treeText.userId = this.userInfo.userId;
            this.getBaseCompanyList(this.treeText, prop);
          }
        }
      }
      // // 抄送人2
      // if (prop == "fCcpeople2") {
      //   if (
      //     this.formData.fIssueunitid == "" ||
      //     this.formData.fIssueunitid == null
      //   ) {
      //     this.$message.error("受检单位2不能为空");
      //   } else {
      //     this.candidate = "选择抄送人2";
      //     this.treeText.companyId = this.formData.fIssueunitid;
      //     this.treeText.userId = this.userInfo.userId;
      //     this.getBaseCompanyList(this.treeText, prop);
      //   }
      // }
    },
    selectChange(value, index, prop) {
      // console.log("selectChange", value, index, prop);
      if (prop == "fSubsignname1") {
        //签收人fSubsignname1
        this.formData.fSubsignid1 = value.value;
        this.formData.fSubsignname1 = value.label;
      }

      //// 判断两个受检单位
      // if (prop == "fUnittype" && value != "集团公司指令") {
      //   this.FromShow = this.FromShowText1;
      // } else if (prop == "fUnittype" && value == "集团公司指令") {
      //   //受检项目
      //   if (
      //     this.treeRow.fCompanyids != null &&
      //     this.treeRow.fCompanyids != ""
      //   ) {
      //     this.FromShow = this.FromShowText2;
      //     this.formData.fCheckunit2 = this.treeRow.fCompanynames;
      //     this.formData.fCheckunit2id = this.treeRow.fCompanyids;
      //   }
      // }
      //// 判断两个受检单位
    },
    //弹框--- 树结构
    getTrees(id) {
      var treeText = {
        companyId: id,
        userId: this.userInfo.userId,
      };
      this.loadingEditDialogTree = true;
      getUserCompanyTreeLists(treeText)
        .then((res) => {
          if (res.errcode == 0) {
            this.dialogEditVisibleTree = true;
            this.loadingEditDialogTree = false;
            var companyTree = res.data.userCompanyTreeList;
            this.treeData = this.commonJs.tranListToTreeData(companyTree);

            if (
              this.formData.fPatrolprojectid != "" &&
              this.formData.fPatrolprojectid != null
            ) {
              this.checkData[0] = this.formData.fPatrolprojectid;
            }
          } else {
            this.$message.error(res.msg);
            this.loadingEditDialogTree = false;
            // this.$message.error("获取组织机构失败");
            return false;
          }
        })
        .catch(() => {
          this.loadingEditDialogTree = false;
          return false;
        });
    },
    getTree(id) {
      var treeText = {
        companyId: id,
        userId: this.userInfo.userId,
      };
      this.loadingEditDialogTree = true;
      getUserCompanyTreeListXm(treeText)
        .then((res) => {
          if (res.errcode == 0) {
            this.dialogEditVisibleTree = true;
            this.loadingEditDialogTree = false;
            var companyTree = res.data.userCompanyTreeList;
            this.treeData = this.commonJs.tranListToTreeData(companyTree);
            if (
              this.formData.fPatrolprojectid != "" &&
              this.formData.fPatrolprojectid != null
            ) {
              this.checkData[0] = this.formData.fPatrolprojectid;
            }
          } else {
            this.$message.error(res.msg);
            this.loadingEditDialogTree = false;
            // this.$message.error("获取组织机构失败");
            return false;
          }
        })
        .catch(() => {
          this.loadingEditDialogTree = false;
          return false;
        });
    },
    handleNodeClick(data) {
      // console.log("选树", data);
      // 受检单位
      if (this.propText == "fCheckunit") {
        this.treeRows = data;
      }
      // 受检项目
      if (this.propText == "fCheckproject") {
        this.treeRow = data;
      }
    },
    //弹框--- 树结构

    // 多选方法
    selectionChange() {},
    // 排序方法
    sortChange() {},

    // 树选人
    // 树结构
    getBaseCompanyList(data, prop) {
      this.departmentList = [];
      this.getUserInitialList = [];
      this.num = null;

      if (prop == "fSubsignname1" || prop == "fSubsignname2") {
        // 单选
        this.newData = [];
        this.personList = [];
        this.checkboxGroup1 = [];
        this.dialogEditVisibleTree_p = true;
        this.loadingEditDialogTree_p = true;
        getUserCompanyTreeList(data)
          .then((res) => {
            this.loadingEditDialogTree_p = false;
            // this.loadingEditDialogTree_p2 = false;
            if (res.errcode == 0) {
              this.companyInfo = this.commonJs.tranListToTreeData(
                res.data.userCompanyTreeList
              );

              console.log("1111", this.companyInfo);
              // 全部人员
              // if (this.propText == "fCcpeople" || this.propText == "fCcpeople2") {
              res.data.userCompanyTreeList.map((item) => {
                this.getUser(item.fCompanyid);
              });
              // }
              // 全部人员
            } else {
              this.$message.error("获取组织机构单位", res.msg);
            }
          })
          .catch((error) => {
            console.log("获取组织机构单位,接口报错", error);
          });
      } else if (prop == "fCcpeople" || prop == "fCcpeople2") {
        // 多选
        let companyInfoList = [];
        var flag = true;
        this.companyInfo = [];
        this.newData2 = [];
        this.personList2 = [];
        this.checkboxGroup2 = [];
        this.dialogEditVisibleTree_p2 = true;
        // this.loadingEditDialogTree_p2 = true;

        // 下发指令单位
        if (
          this.formData.fIssueunit != "" &&
          this.formData.fIssueunit != null &&
          this.formData.fIssueunitid != "" &&
          this.formData.fIssueunitid != null
        ) {
          companyInfoList.push({
            fCompanyid: this.formData.fIssueunitid,
            fShortname: this.formData.fIssueunit,
          });
        }

        // 受检单位1
        if (
          this.formData.fCheckunit != "" &&
          this.formData.fCheckunit != null &&
          this.formData.fCheckunitid != "" &&
          this.formData.fCheckunitid != null
        ) {
          companyInfoList.push({
            fCompanyid: this.formData.fCheckunitid,
            fShortname: this.formData.fCheckunit,
          });
        }
        // 受检单位2
        if (
          this.formData.fCheckunit2 != "" &&
          this.formData.fCheckunit2 != null &&
          this.formData.fCheckunit2id != "" &&
          this.formData.fCheckunit2id != null
        ) {
          companyInfoList.push({
            fCompanyid: this.formData.fCheckunit2id,
            fShortname: this.formData.fCheckunit2,
          });
        }
        // 受检项目
        if (
          this.formData.fCheckproject != "" &&
          this.formData.fCheckproject != null &&
          this.formData.fCheckprojectid != "" &&
          this.formData.fCheckprojectid != null
        ) {
          companyInfoList.push({
            fCompanyid: this.formData.fCheckprojectid,
            fShortname: this.formData.fCheckproject,
          });
        }
        // 去重
        for (let index = 0; index < companyInfoList.length; index++) {
          flag = true;
          for (let y = 0; y < this.companyInfo.length; y++) {
            if (
              this.companyInfo[y].fCompanyid ==
              companyInfoList[index].fCompanyid
            ) {
              flag = false;
            }
          }
          if (flag) {
            this.companyInfo.push(companyInfoList[index]);
          }
        }
        console.log("2222", this.companyInfo);

        // 去重

        // console.log("companyInfo", this.companyInfo);
        // 全部人员
        this.companyInfo.map((item) => {
          this.getUser(item.fCompanyid);
        });
        // 全部人员
      }
    },

    //点击树  调部门
    selectCompany(e) {
      this.departmentList = [];
      this.personList = []; //单选
      // this.personList2 = []; //多选
      this.num = null;
      this.getBaseDepartmentUserFun(e.fCompanyid);
    },

    selectCompanys(e, index) {
      for (let i in this.companyInfo) {
        if (parseFloat(i) === index) {
          this.companyInfo[i].show = true;
        } else {
          this.companyInfo[i].show = false;
        }
      }
      this.departmentList = [];
      // this.personList = []; //单选
      this.personList2 = []; //多选

      this.num = null;
      this.getBaseDepartmentUserFun(e.fCompanyid);
    },

    // 部门管理-查询部门列表以及下属人员
    getBaseDepartmentUserFun(id) {
      getBaseDepartmentUser({ fCompanyid: id })
        .then((res) => {
          if (res.errcode == 0) {
            this.departmentList = res.data.childList;
          } else {
            this.$message.error("部门管理-查询部门列表以及下属人员", res.msg);
          }
        })
        .catch((error) => {
          console.log("部门管理-查询部门列表以及下属人员,接口报错", error);
        });
    },
    // 选择部门
    seletDepartment(e) {
      this.num = e.fDepartmentId;
      let obj = {};
      if (
        this.propText == "fSubsignname1" ||
        this.propText == "fSubsignname2"
      ) {
        // 单选
        this.personList = [];
        this.personList = e.personList.reduce(function (item, next) {
          //item为没有重复id的数组，next为当前对象
          obj[next.fUserid]
            ? ""
            : (obj[next.fUserid] = true && item.push(next));
          return item;
        }, []);

        // 处理选人回填--单选
        if (
          (this.propText == "fSubsignname1" &&
            this.formData.fSubsignname1 != "" &&
            this.formData.fSubsignname1 != null) ||
          (this.propText == "fSubsignname2" &&
            this.formData.fSubsignname2 != "" &&
            this.formData.fSubsignname2 != null)
        ) {
          this.personList.map((item) => {
            if (this.formData.fSubsignid == item.fUserid) {
              this.newData = item;
              this.checkboxGroup1 = item.fUserid;
            }
          });
        }
        // 处理选人回填--单选
      } else if (
        this.propText == "fCcpeople" ||
        this.propText == "fCcpeople2"
      ) {
        // 多选
        this.personList2 = [];
        this.personList2 = e.personList.reduce(function (item, next) {
          //item为没有重复id的数组，next为当前对象
          obj[next.fUserid]
            ? ""
            : (obj[next.fUserid] = true && item.push(next));
          return item;
        }, []);
      }
    },

    // 单选--选人
    selectRealname(e, data) {
      data.map((item) => {
        if (e == item.fUserid) {
          this.newData = item;
        }
      });
    },
    // 多选--选人
    selectRealname2(e, data) {
      this.allUserInfo = this.allUserInfo.concat(data);
      let obj = {};
      let reduce = [];
      reduce = this.allUserInfo.reduce((item, next) => {
        //item为没有重复id的数组，next为当前对象
        obj[next.fUserid] ? "" : (obj[next.fUserid] = true && item.push(next));
        return item;
      }, []);

      this.newData2 = [];
      reduce.map((item) => {
        this.checkboxGroup2.map((i) => {
          if (item.fUserid == i) {
            this.newData2.push(item);
          }
        });
      });
    },
    // 删除用户--多选
    deteleUser(id) {
      this.newData2 = this.newData2.filter((item) => {
        return item.fUserid != id;
      });
      this.checkboxGroup2 = this.checkboxGroup2.filter((item) => {
        return item != id;
      });
    },
    // 保存
    submitMember(num) {
      if (num == 0) {
        // 单选
        if (this.propText == "fSubsignname1") {
          // 指定签收人1
          this.formData.fSubsignid1 = this.newData.fUserid;
          this.formData.fSubsignname1 = this.newData.fRealname;
        }
        if (this.propText == "fSubsignname2") {
          // 指定签收人2
          this.formData.fSubsignid2 = this.newData.fUserid;
          this.formData.fSubsignname2 = this.newData.fRealname;
        }
        this.dialogEditVisibleTree_p = false;
      } else if (num == 1) {
        // 多选
        if (this.propText == "fCcpeople") {
          // 抄送人1
          this.userList = [];
          this.userListId = [];
          console.log(8888, this.newData2);
          this.newData2.map((item) => {
            this.userList.push(item.fRealname);
            this.userListId.push(item.fUserid);
          });
          // if(aaa)
          // companyNature
          this.formData.fCcpeople = this.userList.join(","); //抄送人姓名集合
          this.formData.fCcpeopleid = this.userListId.join(","); //抄送人id集合
        }
        if (this.propText == "fCcpeople2") {
          // 抄送人2
          this.userList = [];
          this.userListId = [];
          this.newData2.map((item) => {
            this.userList.push(item.fRealname);
            this.userListId.push(item.fUserid);
          });

          this.formData.fCcpeople2 = this.userList.join(","); //抄送人姓名集合
          this.formData.fCcpeopleid2 = this.userListId.join(","); //抄送人id集合
        }

        this.dialogEditVisibleTree_p2 = false;
      }
    },

    // 全部人--多选
    getUser(id) {
      getBaseDepartmentUser({ fCompanyid: id })
        .then((res) => {
          if (res.errcode == 0) {
            res.data.childList.map((v) => {
              v.personList.map((item) => {
                this.getUserInitialList.push(item);
              });
            });
            // 处理选人回填--多选
            // 抄送人1
            if (
              this.propText == "fCcpeople" &&
              this.formData.fCcpeople != "" &&
              this.formData.fCcpeople != null
            ) {
              this.newData2 = [];
              this.checkboxGroup2 = [];
              this.allUserInfo = [];

              this.getUserInitialList.map((item) => {
                this.formData.fCcpeopleid.split(",").map((v) => {
                  if (v == item.fUserid) {
                    this.newData2.push(item);
                    this.checkboxGroup2.push(item.fUserid);
                    this.allUserInfo.push(item);
                  }
                });
              });
            }
            // 抄送人2

            if (
              this.propText == "fCcpeople2" &&
              this.formData.fCcpeople2 != "" &&
              this.formData.fCcpeople2 != null
            ) {
              this.newData2 = [];
              this.checkboxGroup2 = [];
              this.allUserInfo = [];

              this.getUserInitialList.map((item) => {
                this.formData.fCcpeopleid2.split(",").map((v) => {
                  if (v == item.fUserid) {
                    this.newData2.push(item);
                    this.checkboxGroup2.push(item.fUserid);
                    this.allUserInfo.push(item);
                  }
                });
              });
            }
            // 处理选人回填--多选

            // 单选回填
            // 指定人1
            if (
              this.propText == "fSubsignname1" &&
              this.formData.fSubsignname1 != "" &&
              this.formData.fSubsignname1 != null
            ) {
              this.newData = [];
              this.checkboxGroup1 = [];
              this.getUserInitialList.map((item) => {
                // this.formData.fCcpeopleid2.split(",").map((v) => {
                if (this.formData.fSubsignid1 == item.fUserid) {
                  this.newData = item;
                  this.checkboxGroup1 = item.fUserid;
                }
                // });
              });
            }
            // 指定人2
            if (
              this.propText == "fSubsignname2" &&
              this.formData.fSubsignname2 != "" &&
              this.formData.fSubsignname2 != null
            ) {
              this.newData = [];
              this.checkboxGroup1 = [];
              this.getUserInitialList.map((item) => {
                // this.formData.fCcpeopleid2.split(",").map((v) => {
                if (this.formData.fSubsignid2 == item.fUserid) {
                  this.newData = item;
                  this.checkboxGroup1 = item.fUserid;
                }
                // });
              });
            }
            // 单选回填
          } else {
            this.$message.error(res.msg);
            console.log("部门管理-查询部门列表以及下属人员,接口报错");
          }
        })
        .catch((error) => {
          console.log("部门管理-查询部门列表以及下属人员", error);
        });
    },
    // 树选人
  },
};
</script>

<style scoped lang="less">
.printTables {
  background: #fff;
  display: flex;
  justify-content: end;
  padding: 5px;
  margin-top: 10px;
}

.dialogBody {
  padding: 3px 20px;
  height: 80%;
  overflow-y: auto;
}

.baseTitle {
  /* border: 1px solid #0c204d; */
  border-bottom: 1px solid #0c204d;
  height: 30px;
  line-height: 30px;
  position: relative;
  padding-left: 15px;
}

.baseTitle::after {
  display: block;
  content: "";
  height: 30px;
  width: 5px;
  position: absolute;
  left: 0;
  top: 0;
  background: #0c204d;
}

/* 弹框 */
.publicForm {
  display: flex;
}

.publicForm .mouldForm /deep/ .el-form-item__content {
  margin-left: 120px !important;
}

.publicFormBox {
  width: 50%;
  height: 100%;
}

.closure /deep/ .el-input__suffix {
  left: 91%;
}

/* 树选人 */
.addMemberCheckBox /deep/ .el-tree {
  overflow: hidden;
}

.addMemberCheckBox {
  display: flex;

  .addMemberCheckTree {
    width: 30%;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(221, 221, 221, 1);
    box-sizing: border-box;

    .companyBox {
      height: 70%;
      box-sizing: border-box;
      overflow-y: auto;

      // 自己生成
      .companyBox_box {
        color: #555;
        width: 100%;
        height: 30px;
        line-height: 30px;
        background: aliceblue;
        border-radius: 28px 0 0 28px;
        font-size: 12px !important;
        font-weight: 700 !important;
        padding-left: 30px;
      }

      // 自己生成
    }

    .departmentBox {
      height: 30%;
      border-top: 0.5px solid rgba(221, 221, 221, 1);
      /* border: 1px solid red; */
      display: flex;
      flex-wrap: wrap;
      align-content: flex-start;
      overflow: hidden;
      overflow-y: auto;

      .departmentTitle {
        width: 77px;
        text-align: center;
        height: 40px;
        margin: 5px;
        // border: 1px solid green;
        border-radius: 8px;
        background: #d4daea;
        overflow: hidden;

        a {
          width: 100%;
          height: 100%;
          display: block;
          text-decoration: none;
        }
      }
    }
  }

  .selectMemberLeft {
    display: flex;
    align-items: center;
  }

  .addMemberCheckLeft {
    width: 70%;
    padding: 0 0 0 20px;
    border-top: 1px solid rgba(221, 221, 221, 1);
    border-bottom: 1px solid rgba(221, 221, 221, 1);
    border-right: 1px solid rgba(221, 221, 221, 1);

    .addMemberCheck {
      width: 150px;
      height: 64px;
      border-radius: 2px;
      display: flex;
      align-items: center;
      position: absolute;
      top: 0;
      left: 0;
    }
  }

  .addMemberCheckLefts {
    width: 52%;
  }
}

.newlyAdded_btns {
  height: 8%;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.addMemberCheck .MemberIcon {
  height: 62px;
  width: 64px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(241, 241, 241, 1);
}

.MemberIcon img {
  width: 37.81px;
  height: 39.38px;
  border-radius: 50%;
}

.MemberDetailInfos {
  position: relative;
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;

  .name {
    color: rgba(51, 51, 51, 1);
    font-size: 12px;
    height: 20px;
    line-height: 20px;
  }

  .hostName {
    color: rgba(128, 125, 125, 1);
    font-size: 12px;
    height: 20px;
    line-height: 20px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.MemberIcon .name {
  color: rgba(51, 51, 51, 1);
  font-size: 12px;
  height: 20px;
  line-height: 20px;
}

.MemberIcon .hostName {
  color: rgba(128, 125, 125, 1);
  font-size: 12px;
  height: 20px;
  line-height: 20px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.activetext {
  color: rgba(197, 227, 255, 1);
  background: #2b5a9d;
}

// 多选人
.addMemberCheckBox .selectPerson {
  width: 18%;
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(221, 221, 221, 1);
  margin-left: 15px;
  box-sizing: border-box;

  .selectPersonTitle {
    height: 28px;
    line-height: 28px;
    text-align: center;
    background: rgba(241, 241, 241, 1);
    border-bottom: 1px solid rgba(221, 221, 221, 1);
    color: rgba(128, 125, 125, 1);
    font-size: 12px;
  }

  .selectPersonData {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-y: auto;

    .selectPersonDataBox {
      width: 165px;
      height: 72px;
      border-radius: 2px;
      border: 1px solid rgba(222, 222, 222, 1);
      margin: 8px 0;
      display: flex;
      position: relative;

      .MemberIcon {
        height: 100%;
        width: 64px;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-right: 8px;
        background: rgba(241, 241, 241, 1);

        img {
          width: 37.81px;
          height: 39.38px;
          border-radius: 50%;
        }
      }

      .MemberDetailInfo1 {
        position: relative;
        flex: 1;
        height: 100%;
        padding: 14px 0;
        overflow: hidden;

        .name {
          color: rgba(51, 51, 51, 1);
          font-size: 12px;
          height: 20px;
          line-height: 5px;
          white-space: nowrap;
        }

        .hostName {
          color: rgba(128, 125, 125, 1);
          font-size: 12px;
          height: 20px;
          line-height: 10px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }
    }
  }
}

.MemberDetailInfo::after {
  position: absolute;
  width: 30px;
  height: 30px;
  display: block;
  background: url("../../../../assets/img/organization/yes.png") no-repeat;
  background-size: 100% 100%;
  right: 0;
  top: 0;
}

.deleteUser {
  position: absolute;
  width: 22px;
  height: 22px;
  display: block;
  background: url("../../../../assets/img/organization/no.png") no-repeat;
  background-size: 100% 100%;
  right: 0;
  top: 0;
}

// 多选人

.samllDialogs {
  display: flex;
  margin: 0 20px;
  padding-top: 50px;

  .treeModule {
    flex: 1;
  }
}

.addMemberCheckLeft /deep/ .el-radio-button {
  display: inline-block;
  width: 150px;
  height: 64px;
  position: relative;
  margin: 8px;
  border-radius: 2px;
  overflow: hidden;
  /* border: 1px solid rgba(222, 222, 222, 1); */
}

.addMemberCheckLeft /deep/ .el-radio-button__inner {
  border: 1px solid rgba(222, 222, 222, 1);
  border-radius: 2px;
  width: 100%;
  height: 100%;
  position: absolute;
  left: 0;
  top: 0;
}

.addMemberCheckLeft /deep/ .el-radio-group {
  flex-wrap: wrap;
  font-size: 0;
  display: flex;
  /* flex-direction: column; */
}

/* 树选人 */
// 树弹框
#department1 /deep/ .el-dialog {
  width: 600px !important;
}

// 树弹框

/* 弹框 */
</style>